package com.lebang.service.cences;

import com.lebang.component.RedisClient;
import com.lebang.domain.CencesNewHand;
import com.lebang.entity.TaskRewards;
import com.lebang.example.CencesNewHandExample;
import com.lebang.mapper.CencesNewHandMapper;
import com.lebang.mapper.LbbMemberMapper;
import com.lebang.mapper.TaskRewardsMapper;
import com.lebang.mapper.TaskRewardsRecordMapper;
import com.lebang.model.MyConfig;
import com.lebang.model.cences.CencesMsg;
import com.lebang.model.cences.CencesNewHandModel;
import com.lebang.model.cences.NewHandRecordCount;
import com.lebang.model.enums.NewHandTaskEnum;
import com.lebang.service.BaseService;
import com.lebang.service.mongodb.CencesMsgMongodb;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import static com.lebang.controller.api.TaskClickController.newHandKey;

/**
 * 新手任务
 *
 * @Author xwj
 * @Date 2020-04-09
 */
@Service
public class CencesNewHandService extends BaseService<CencesNewHand, Integer, CencesNewHandExample> {
    @Autowired
    private CencesNewHandMapper baseMapper;
    @Autowired
    private LbbMemberMapper lbbMemberMapper;

    @Autowired
    private TaskRewardsMapper taskRewardsMapper;

    @Autowired
    private TaskRewardsRecordMapper taskRewardsRecordMapper;

    @Autowired
    private RedisClient redisClient;

    @Autowired
    private CencesMsgMongodb cencesMsgMongodb;


    public void starDataInit(LocalDateTime end) {
        this.starDataInit(end, null);
    }

    /**
     * 统计指定日期的新手任务数据
     *
     * @param end   结束日期
     * @param brand 渠道
     */
    public void starDataInit(LocalDateTime end, List<String> brand) {
        long starTime = System.currentTimeMillis();
        //star 开始日期  end 结束日期
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd");
        LocalDateTime star = end.minusDays(1);

        //所有的渠道来源
        if (brand == null) {
            brand = lbbMemberMapper.selectBrand();
        }

        //转换成yyyyMMdd格式
        int time = Integer.parseInt(end.toLocalDate().minusDays(1).format(df));


        //全渠道新用户
        CencesNewHand allBrandNewCencesNewHand = new CencesNewHand(time, "all", 1, 1, MyConfig.getEnv());
        //全渠道老用户
        CencesNewHand allBrandOldCencesNewHand = new CencesNewHand(time, "all", 0, 1,MyConfig.getEnv());
        //全渠道全部用户
        CencesNewHand allBrandAllCencesNewHand = new CencesNewHand(time, "all", 2, 1,MyConfig.getEnv());

        //获取所有的任务
        List<TaskRewards> allTaskRewards = taskRewardsMapper.selectByExample(null);
        Map<Integer,List<TaskRewards>> allTaskRewardsMap = allTaskRewards.stream().collect(Collectors.groupingBy(TaskRewards::getId));

        //新用户分渠道
        List<NewHandRecordCount> newUserCounts = taskRewardsRecordMapper.selectNewUserCount(star, end);
        newUserCounts.forEach(s->{s.setAppStoreRewardId(s.getAppStore()+":"+s.getRewardsId());});
        Map<String,List<NewHandRecordCount>> newUserCountsMap = newUserCounts.stream().collect(Collectors.groupingBy(NewHandRecordCount::getAppStoreRewardId));
        //老用户分渠道
        List<NewHandRecordCount> oldUserCounts = taskRewardsRecordMapper.selectOldUserCount(star, end);
        oldUserCounts.forEach(s->{s.setAppStoreRewardId(s.getAppStore()+":"+s.getRewardsId());});
        Map<String,List<NewHandRecordCount>> oldUserCountsMap = oldUserCounts.stream().collect(Collectors.groupingBy(NewHandRecordCount::getAppStoreRewardId));
        //全部用户分渠道
        List<NewHandRecordCount> allUserCounts = taskRewardsRecordMapper.selectAllUserCount(star, end);
        allUserCounts.forEach(s->{s.setAppStoreRewardId(s.getAppStore()+":"+s.getRewardsId());});
        Map<String,List<NewHandRecordCount>> allUserCountsMap = allUserCounts.stream().collect(Collectors.groupingBy(NewHandRecordCount::getAppStoreRewardId));


        //分渠道
        for (String s : brand) {

            //单渠道新用户
            CencesNewHand singleNewCencesNewHand = new CencesNewHand();
            singleNewCencesNewHand.setAppId(MyConfig.getEnv());
            //单渠道老用户
            CencesNewHand singleOldCencesNewHand = new CencesNewHand();
            singleOldCencesNewHand.setAppId(MyConfig.getEnv());
            //单渠道全部用户
            CencesNewHand singleAllCencesNewHand = new CencesNewHand();
            singleAllCencesNewHand.setAppId(MyConfig.getEnv());

            //"小试牛刀"
            singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.XSND.getIndex(), star, end, s, singleNewCencesNewHand,newUserCountsMap,allTaskRewardsMap);
            singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.XSND.getIndex(), star, end, s, singleAllCencesNewHand,allUserCountsMap,allTaskRewardsMap);
            singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.XSND.getIndex(), star, end, s, singleOldCencesNewHand,oldUserCountsMap,allTaskRewardsMap);

            // "新手红包"
            // singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.NEW_HAND.getIndex(),star,end,s,singleNewCencesNewHand);
            // singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.NEW_HAND.getIndex(),star,end,s,singleAllCencesNewHand);
            // singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.NEW_HAND.getIndex(),star,end,s,singleOldCencesNewHand);

            // "赚钱攻略"
            singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.EARN_WAY.getIndex(), star, end, s, singleNewCencesNewHand,newUserCountsMap,allTaskRewardsMap);
            singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.EARN_WAY.getIndex(), star, end, s, singleAllCencesNewHand,allUserCountsMap,allTaskRewardsMap);
            singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.EARN_WAY.getIndex(), star, end, s, singleOldCencesNewHand,oldUserCountsMap,allTaskRewardsMap);

            //"开安装权限"
            singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.INSTALL.getIndex(), star, end, s, singleNewCencesNewHand,newUserCountsMap,allTaskRewardsMap);
            singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.INSTALL.getIndex(), star, end, s, singleAllCencesNewHand,allUserCountsMap,allTaskRewardsMap);
            singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.INSTALL.getIndex(), star, end, s, singleOldCencesNewHand,oldUserCountsMap,allTaskRewardsMap);

            // "开访问权限"
            singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.ACCESS.getIndex(), star, end, s, singleNewCencesNewHand,newUserCountsMap,allTaskRewardsMap);
            singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.ACCESS.getIndex(), star, end, s, singleAllCencesNewHand,allUserCountsMap,allTaskRewardsMap);
            singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.ACCESS.getIndex(), star, end, s, singleOldCencesNewHand,oldUserCountsMap,allTaskRewardsMap);

            // "开推送权限"
            singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.PUSH.getIndex(), star, end, s, singleNewCencesNewHand,newUserCountsMap,allTaskRewardsMap);
            singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.PUSH.getIndex(), star, end, s, singleAllCencesNewHand,allUserCountsMap,allTaskRewardsMap);
            singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.PUSH.getIndex(), star, end, s, singleOldCencesNewHand,oldUserCountsMap,allTaskRewardsMap);

            //"截图任务"
            singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.PICTURE.getIndex(), star, end, s, singleNewCencesNewHand,newUserCountsMap,allTaskRewardsMap);
            singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.PICTURE.getIndex(), star, end, s, singleAllCencesNewHand,allUserCountsMap,allTaskRewardsMap);
            singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.PICTURE.getIndex(), star, end, s, singleOldCencesNewHand,oldUserCountsMap,allTaskRewardsMap);

            //"试玩任务"
            // singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.DEMO.getIndex(),star,end,s,singleNewCencesNewHand);
            //singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.DEMO.getIndex(),star,end,s,singleAllCencesNewHand);
            // singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.DEMO.getIndex(),star,end,s,singleOldCencesNewHand);

            //  "高额任务"
            singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.HIGH.getIndex(), star, end, s, singleNewCencesNewHand,newUserCountsMap,allTaskRewardsMap);
            singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.HIGH.getIndex(), star, end, s, singleAllCencesNewHand,allUserCountsMap,allTaskRewardsMap);
            singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.HIGH.getIndex(), star, end, s, singleOldCencesNewHand,oldUserCountsMap,allTaskRewardsMap);

            // "微信小程序任务"
//                singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.WECHAT.getIndex(),star,end,s,singleNewCencesNewHand);
//                singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.WECHAT.getIndex(),star,end,s,singleAllCencesNewHand);
//                singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.WECHAT.getIndex(),star,end,s,singleOldCencesNewHand);

            // "多游试玩任务"
//                singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.GAME_DEMO.getIndex(),star,end,s,singleNewCencesNewHand);
//                singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.GAME_DEMO.getIndex(),star,end,s,singleAllCencesNewHand);
//                singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.GAME_DEMO.getIndex(),star,end,s,singleOldCencesNewHand);

            //  "pc蛋蛋"
//                singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.PC_EGG.getIndex(),star,end,s,singleNewCencesNewHand);
//                singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.PC_EGG.getIndex(),star,end,s,singleAllCencesNewHand);
//                singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.PC_EGG.getIndex(),star,end,s,singleOldCencesNewHand);

            //  "聚享玩"
//                singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.ENJOY_GAME.getIndex(),star,end,s,singleNewCencesNewHand);
//                singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.ENJOY_GAME.getIndex(),star,end,s,singleAllCencesNewHand);
//                singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.ENJOY_GAME.getIndex(),star,end,s,singleOldCencesNewHand);

            //  "91淘金试玩"
//                singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.GOLD_DEMO.getIndex(),star,end,s,singleNewCencesNewHand);
//                singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.GOLD_DEMO.getIndex(),star,end,s,singleAllCencesNewHand);
//                singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.GOLD_DEMO.getIndex(),star,end,s,singleOldCencesNewHand);

            //  "搜搜任务"
//                singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.SOSO.getIndex(),star,end,s,singleNewCencesNewHand);
//                singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.SOSO.getIndex(),star,end,s,singleAllCencesNewHand);
//                singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.SOSO.getIndex(),star,end,s,singleOldCencesNewHand);

            //   "搜搜糯米狗任务"
//                singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.SOSO_DOG.getIndex(),star,end,s,singleNewCencesNewHand);
//                singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.SOSO_DOG.getIndex(),star,end,s,singleAllCencesNewHand);
//                singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.SOSO_DOG.getIndex(),star,end,s,singleOldCencesNewHand);

            //  "完成搜搜兼职咸鱼任务"
//                singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.SOSO_FISH.getIndex(),star,end,s,singleNewCencesNewHand);
//                singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.SOSO_FISH.getIndex(),star,end,s,singleAllCencesNewHand);
//                singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.SOSO_FISH.getIndex(),star,end,s,singleOldCencesNewHand);

            //  "每日必赚"
            singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.EARN_DAY.getIndex(), star, end, s, singleNewCencesNewHand,newUserCountsMap,allTaskRewardsMap);
            singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.EARN_DAY.getIndex(), star, end, s, singleAllCencesNewHand,allUserCountsMap,allTaskRewardsMap);
            singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.EARN_DAY.getIndex(), star, end, s, singleOldCencesNewHand,oldUserCountsMap,allTaskRewardsMap);

            //  "新闻赚"
//                singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.NEWS.getIndex(),star,end,s,singleNewCencesNewHand);
//                singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.NEWS.getIndex(),star,end,s,singleAllCencesNewHand);
//                singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.NEWS.getIndex(),star,end,s,singleOldCencesNewHand);

            //  "笑话赚"
            singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.JOY.getIndex(), star, end, s, singleNewCencesNewHand,newUserCountsMap,allTaskRewardsMap);
            singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.JOY.getIndex(), star, end, s, singleAllCencesNewHand,allUserCountsMap,allTaskRewardsMap);
            singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.JOY.getIndex(), star, end, s, singleOldCencesNewHand,oldUserCountsMap,allTaskRewardsMap);

            //  "访问权限开启"
//                singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.ACCESS_OPEN.getIndex(),star,end,s,singleNewCencesNewHand);
//                singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.ACCESS_OPEN.getIndex(),star,end,s,singleAllCencesNewHand);
//                singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.ACCESS_OPEN.getIndex(),star,end,s,singleOldCencesNewHand);

            //  "走路赚"
                singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.WALK.getIndex(),star,end,s,singleNewCencesNewHand,newUserCountsMap,allTaskRewardsMap);
                singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.WALK.getIndex(),star,end,s,singleAllCencesNewHand,allUserCountsMap,allTaskRewardsMap);
                singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.WALK.getIndex(),star,end,s,singleOldCencesNewHand,oldUserCountsMap,allTaskRewardsMap);

            //  "鱼玩盒子"
//                singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.FISH_BOX.getIndex(),star,end,s,singleNewCencesNewHand);
//                singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.FISH_BOX.getIndex(),star,end,s,singleAllCencesNewHand);
//                singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.FISH_BOX.getIndex(),star,end,s,singleOldCencesNewHand);

            // "第二次每日必赚"
            singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.SECOND_EARN_DAY.getIndex(),star,end,s,singleNewCencesNewHand,newUserCountsMap,allTaskRewardsMap);
            singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.SECOND_EARN_DAY.getIndex(),star,end,s,singleAllCencesNewHand,allUserCountsMap,allTaskRewardsMap);
            singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.SECOND_EARN_DAY.getIndex(),star,end,s,singleOldCencesNewHand,oldUserCountsMap,allTaskRewardsMap);

            // "第三次每日必赚"
            singleNewCencesNewHand = getSingleNewTask(NewHandTaskEnum.THIRD_EARN_DAY.getIndex(),star,end,s,singleNewCencesNewHand,newUserCountsMap,allTaskRewardsMap);
            singleAllCencesNewHand = getSingleAllTask(NewHandTaskEnum.THIRD_EARN_DAY.getIndex(),star,end,s,singleAllCencesNewHand,allUserCountsMap,allTaskRewardsMap);
            singleOldCencesNewHand = getSingleOldTask(NewHandTaskEnum.THIRD_EARN_DAY.getIndex(),star,end,s,singleOldCencesNewHand,oldUserCountsMap,allTaskRewardsMap);


            setOtherFild(time, 1, s, singleNewCencesNewHand);
            setOtherFild(time, 2, s, singleAllCencesNewHand);
            setOtherFild(time, 0, s, singleOldCencesNewHand);


            baseMapper.insertAll(singleNewCencesNewHand);
            baseMapper.insertAll(singleAllCencesNewHand);
            baseMapper.insertAll(singleOldCencesNewHand);

            //全渠道新用户求和点击量，完成量
            sumData(singleNewCencesNewHand, allBrandNewCencesNewHand);
            //全渠道老用户求和点击量，完成量
            sumData(singleOldCencesNewHand, allBrandOldCencesNewHand);
            //全渠道全用户求和点击量，完成量
            sumData(singleAllCencesNewHand, allBrandAllCencesNewHand);

        }


        //全渠道新用户完成率
        devideFinishRate(allBrandNewCencesNewHand);
        //全渠道老用户完成率
        devideFinishRate(allBrandOldCencesNewHand);
        //全渠道全用户完成率
        devideFinishRate(allBrandAllCencesNewHand);


        baseMapper.insertAll(allBrandNewCencesNewHand);
        baseMapper.insertAll(allBrandOldCencesNewHand);
        baseMapper.insertAll(allBrandAllCencesNewHand);



        cencesMsgMongodb.save(new CencesMsg("新手任务统计",(System.currentTimeMillis() - starTime)));

    }

    /**
     * 统计所有渠道的完成率
     *
     * @param cencesNewHand 新手任务统计
     */
    private void devideFinishRate(CencesNewHand cencesNewHand) {

        //"小试牛刀"
        cencesNewHand.setFinishRate(cencesNewHand.getClickNum() == 0 ? BigDecimal.ZERO : BigDecimal.valueOf(cencesNewHand.getFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getClickNum()), 2, BigDecimal.ROUND_DOWN));

        //"新手红包"
//        cencesNewHand.setNewhandFinishRate(cencesNewHand.getNewhandClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getNewhandFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getNewhandClickNum()),2));

        //"赚钱攻略"
        cencesNewHand.setEarnwayFinishRate(cencesNewHand.getEarnwayClickNum() == 0 ? BigDecimal.ZERO : BigDecimal.valueOf(cencesNewHand.getEarnwayFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getEarnwayClickNum()), 2, BigDecimal.ROUND_DOWN));

        //"开安装权限"
        cencesNewHand.setInstallFinishRate(cencesNewHand.getInstallClickNum() == 0 ? BigDecimal.ZERO : BigDecimal.valueOf(cencesNewHand.getInstallFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getInstallClickNum()), 2, BigDecimal.ROUND_DOWN));

        //"开访问权限"
        cencesNewHand.setAccessFinishRate(cencesNewHand.getAccessClickNum() == 0 ? BigDecimal.ZERO : BigDecimal.valueOf(cencesNewHand.getAccessFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getAccessClickNum()), 2, BigDecimal.ROUND_DOWN));

        //"开推送权限"
        cencesNewHand.setPushFinishRate(cencesNewHand.getPushClickNum() == 0 ? BigDecimal.ZERO : BigDecimal.valueOf(cencesNewHand.getPushFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getPushClickNum()), 2, BigDecimal.ROUND_DOWN));

        //"截图任务"
        cencesNewHand.setPictureFinishRate(cencesNewHand.getPictureClickNum() == 0 ? BigDecimal.ZERO : BigDecimal.valueOf(cencesNewHand.getPictureFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getPictureClickNum()), 2, BigDecimal.ROUND_DOWN));

        //"试玩任务"
//        cencesNewHand.setDemoFinishRate(cencesNewHand.getDemoClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getDemoFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getDemoClickNum()),2));

        //"高额任务"
        cencesNewHand.setHighFinishRate(cencesNewHand.getHighClickNum() == 0 ? BigDecimal.ZERO : BigDecimal.valueOf(cencesNewHand.getHighFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getHighClickNum()), 2, BigDecimal.ROUND_DOWN));

        //"微信小程序任务"
//        cencesNewHand.setWechatFinishRate(cencesNewHand.getWechatClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getWechatFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getWechatClickNum()),2));

        //"多游试玩任务"
//        cencesNewHand.setGamedemoFinishRate(cencesNewHand.getGamedemoClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getGamedemoFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getGamedemoClickNum()),2));

        //"pc蛋蛋"
//        cencesNewHand.setPceggFinishRate(cencesNewHand.getPceggClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getPceggFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getPceggClickNum()),2));

        //"聚享玩"
//        cencesNewHand.setEnjoygameFinishRate(cencesNewHand.getEnjoygameClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getEnjoygameFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getEnjoygameClickNum()),2));

        //"91淘金试玩"
//        cencesNewHand.setGolddemoFinishRate(cencesNewHand.getGolddemoClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getGolddemoFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getGolddemoClickNum()),2));

        //"搜搜任务"
//        cencesNewHand.setSosoFinishRate(cencesNewHand.getSosoClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getSosoFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getSosoClickNum()),2));

        //"搜搜糯米狗任务"
//        cencesNewHand.setSosodogFinishRate(cencesNewHand.getSosodogClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getSosodogFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getSosodogClickNum()),2));


        //"完成搜搜兼职咸鱼任务"
//        cencesNewHand.setSosofishFinishRate(cencesNewHand.getSosofishClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getSosofishFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getSosofishClickNum()),2));

        //"每日必赚"
        cencesNewHand.setEarndayFinishRate(cencesNewHand.getEarndayClickNum() == 0 ? BigDecimal.ZERO : BigDecimal.valueOf(cencesNewHand.getEarndayFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getEarndayClickNum()), 2, BigDecimal.ROUND_DOWN));

        //"新闻赚"
//        cencesNewHand.setNewsFinishRate(cencesNewHand.getNewsClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getNewsFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getNewsClickNum()),2));

        //"笑话赚"
        cencesNewHand.setJoyFinishRate(cencesNewHand.getJoyClickNum() == 0 ? BigDecimal.ZERO : BigDecimal.valueOf(cencesNewHand.getJoyFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getJoyClickNum()), 2, BigDecimal.ROUND_DOWN));

        //"访问权限开启"
//        cencesNewHand.setAccessopenFinishRate(cencesNewHand.getAccessopenClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getAccessopenFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getAccessopenClickNum()),2));

        //"走路赚"
        cencesNewHand.setWalkFinishRate(cencesNewHand.getWalkClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getWalkFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getWalkClickNum()),2,BigDecimal.ROUND_DOWN));

        //"鱼玩盒子"
//        cencesNewHand.setFishboxFinishRate(cencesNewHand.getFishboxClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getFishboxFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getFishboxClickNum()),2));

        // "第二次每日必赚"
        cencesNewHand.setSecondEarndayFinishRate(cencesNewHand.getSecondEarndayClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getSecondEarndayFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getSecondEarndayClickNum()),2,BigDecimal.ROUND_DOWN));

        // "第三次每日必赚"
        cencesNewHand.setThirdEarndayFinishRate(cencesNewHand.getThirdEarndayClickNum()==0?BigDecimal.ZERO:BigDecimal.valueOf(cencesNewHand.getThirdEarndayFinishNum()).divide(BigDecimal.valueOf(cencesNewHand.getThirdEarndayClickNum()),2,BigDecimal.ROUND_DOWN));
    }

    /**
     * 统计所有渠道数据 点击量，完成量
     *
     * @param singleCencesNewHand 单渠道新手任务
     * @param cencesNewHand       新手任务
     */
    private void sumData(CencesNewHand singleCencesNewHand, CencesNewHand cencesNewHand) {

        //"小试牛刀"
        cencesNewHand.setClickNum(cencesNewHand.getClickNum() + (null == singleCencesNewHand.getClickNum() ? 0 : singleCencesNewHand.getClickNum()));
        cencesNewHand.setFinishNum(cencesNewHand.getFinishNum() + (null == singleCencesNewHand.getFinishNum() ? 0 : singleCencesNewHand.getFinishNum()));

        //"新手红包"
//        cencesNewHand.setNewhandClickNum(cencesNewHand.getNewhandClickNum()+(null==singleCencesNewHand.getNewhandClickNum()?0:singleCencesNewHand.getNewhandClickNum()));
//        cencesNewHand.setNewhandFinishNum(cencesNewHand.getNewhandFinishNum()+(null==singleCencesNewHand.getNewhandFinishNum()?0:singleCencesNewHand.getNewhandFinishNum()));

        //"赚钱攻略"
        cencesNewHand.setEarnwayClickNum(cencesNewHand.getEarnwayClickNum() + (null == singleCencesNewHand.getEarnwayClickNum() ? 0 : singleCencesNewHand.getEarnwayClickNum()));
        cencesNewHand.setEarnwayFinishNum(cencesNewHand.getEarnwayFinishNum() + (null == singleCencesNewHand.getEarnwayFinishNum() ? 0 : singleCencesNewHand.getEarnwayFinishNum()));

        //"开安装权限"
        cencesNewHand.setInstallClickNum(cencesNewHand.getInstallClickNum() + (null == singleCencesNewHand.getInstallClickNum() ? 0 : singleCencesNewHand.getInstallClickNum()));
        cencesNewHand.setInstallFinishNum(cencesNewHand.getInstallFinishNum() + (null == singleCencesNewHand.getInstallFinishNum() ? 0 : singleCencesNewHand.getInstallFinishNum()));

        //"开访问权限"
        cencesNewHand.setAccessClickNum(cencesNewHand.getAccessClickNum() + (null == singleCencesNewHand.getAccessClickNum() ? 0 : singleCencesNewHand.getAccessClickNum()));
        cencesNewHand.setAccessFinishNum(cencesNewHand.getAccessFinishNum() + (null == singleCencesNewHand.getAccessFinishNum() ? 0 : singleCencesNewHand.getAccessFinishNum()));

        //"开推送权限"
        cencesNewHand.setPushClickNum(cencesNewHand.getPushClickNum() + (null == singleCencesNewHand.getPushClickNum() ? 0 : singleCencesNewHand.getPushClickNum()));
        cencesNewHand.setPushFinishNum(cencesNewHand.getAccessFinishNum() + (null == singleCencesNewHand.getAccessFinishNum() ? 0 : singleCencesNewHand.getAccessFinishNum()));

        //"截图任务"
        cencesNewHand.setPictureClickNum(cencesNewHand.getPictureClickNum() + (null == singleCencesNewHand.getPictureClickNum() ? 0 : singleCencesNewHand.getPictureClickNum()));
        cencesNewHand.setPictureFinishNum(cencesNewHand.getPictureFinishNum() + (null == singleCencesNewHand.getPictureFinishNum() ? 0 : singleCencesNewHand.getPictureFinishNum()));

        //"试玩任务"
//        cencesNewHand.setDemoClickNum(cencesNewHand.getDemoClickNum()+(null==singleCencesNewHand.getDemoClickNum()?0:singleCencesNewHand.getDemoClickNum()));
//        cencesNewHand.setDemoFinishNum(cencesNewHand.getDemoFinishNum()+(null==singleCencesNewHand.getDemoFinishNum()?0:singleCencesNewHand.getDemoFinishNum()));

        //"高额任务"
        cencesNewHand.setHighClickNum(cencesNewHand.getHighClickNum() + (null == singleCencesNewHand.getHighClickNum() ? 0 : singleCencesNewHand.getHighClickNum()));
        cencesNewHand.setHighFinishNum(cencesNewHand.getHighFinishNum() + (null == singleCencesNewHand.getHighFinishNum() ? 0 : singleCencesNewHand.getHighFinishNum()));

        //"微信小程序任务"
//        cencesNewHand.setWechatClickNum(cencesNewHand.getWechatClickNum()+(null==singleCencesNewHand.getWechatClickNum()?0:singleCencesNewHand.getWechatClickNum()));
//        cencesNewHand.setWechatFinishNum(cencesNewHand.getWechatFinishNum()+(null==singleCencesNewHand.getWechatFinishNum()?0:singleCencesNewHand.getWechatFinishNum()));

        //"多游试玩任务"
//        cencesNewHand.setGamedemoClickNum(cencesNewHand.getGamedemoClickNum()+(null==singleCencesNewHand.getGamedemoClickNum()?0:singleCencesNewHand.getGamedemoClickNum()));
//        cencesNewHand.setGamedemoFinishNum(cencesNewHand.getGamedemoFinishNum()+(null==singleCencesNewHand.getGamedemoFinishNum()?0:singleCencesNewHand.getGamedemoFinishNum()));

        //"pc蛋蛋"
//        cencesNewHand.setPceggClickNum(cencesNewHand.getPceggClickNum()+(null==singleCencesNewHand.getPceggClickNum()?0:singleCencesNewHand.getPceggClickNum()));
//        cencesNewHand.setPceggFinishNum(cencesNewHand.getPceggFinishNum()+(null==singleCencesNewHand.getPceggFinishNum()?0:singleCencesNewHand.getPceggFinishNum()));

        //"聚享玩"
//        cencesNewHand.setEnjoygameClickNum(cencesNewHand.getEnjoygameClickNum()+(null==singleCencesNewHand.getEnjoygameClickNum()?0:singleCencesNewHand.getEnjoygameClickNum()));
//        cencesNewHand.setEnjoygameFinishNum(cencesNewHand.getEnjoygameFinishNum()+(null==singleCencesNewHand.getEnjoygameFinishNum()?0:singleCencesNewHand.getEnjoygameFinishNum()));

        //"91淘金试玩"
//        cencesNewHand.setGolddemoClickNum(cencesNewHand.getGolddemoClickNum()+(null==singleCencesNewHand.getGolddemoClickNum()?0:singleCencesNewHand.getGolddemoClickNum()));
//        cencesNewHand.setGolddemoFinishNum(cencesNewHand.getGolddemoFinishNum()+(null==singleCencesNewHand.getGolddemoFinishNum()?0:singleCencesNewHand.getGolddemoFinishNum()));

        //"搜搜任务"
//        cencesNewHand.setSosoClickNum(cencesNewHand.getSosoClickNum()+(null==singleCencesNewHand.getSosoClickNum()?0:singleCencesNewHand.getSosoClickNum()));
//        cencesNewHand.setSosoFinishNum(cencesNewHand.getSosoFinishNum()+(null==singleCencesNewHand.getSosoFinishNum()?0:singleCencesNewHand.getSosoFinishNum()));

        //"搜搜糯米狗任务"
//        cencesNewHand.setSosodogClickNum(cencesNewHand.getSosodogClickNum()+(null==singleCencesNewHand.getSosodogClickNum()?0:singleCencesNewHand.getSosodogClickNum()));
//        cencesNewHand.setSosodogFinishNum(cencesNewHand.getSosodogFinishNum()+(null==singleCencesNewHand.getSosodogFinishNum()?0:singleCencesNewHand.getSosodogFinishNum()));

        //"完成搜搜兼职咸鱼任务"
//        cencesNewHand.setSosofishClickNum(cencesNewHand.getSosofishClickNum()+(null==singleCencesNewHand.getSosofishClickNum()?0:singleCencesNewHand.getSosofishClickNum()));
//        cencesNewHand.setSosofishFinishNum(cencesNewHand.getSosofishFinishNum()+(null==singleCencesNewHand.getSosofishFinishNum()?0:singleCencesNewHand.getSosofishFinishNum()));

        //"每日必赚"
        cencesNewHand.setEarndayClickNum(cencesNewHand.getEarndayClickNum() + (null == singleCencesNewHand.getEarndayClickNum() ? 0 : singleCencesNewHand.getEarndayClickNum()));
        cencesNewHand.setEarndayFinishNum(cencesNewHand.getEarndayFinishNum() + (null == singleCencesNewHand.getEarndayFinishNum() ? 0 : singleCencesNewHand.getEarndayFinishNum()));

        //"新闻赚"
//        cencesNewHand.setNewsClickNum(cencesNewHand.getNewsClickNum()+(null==singleCencesNewHand.getNewsClickNum()?0:singleCencesNewHand.getNewsClickNum()));
//        cencesNewHand.setNewsFinishNum(cencesNewHand.getNewsFinishNum()+(null==singleCencesNewHand.getNewsFinishNum()?0:singleCencesNewHand.getNewsFinishNum()));

        //"笑话赚"
        cencesNewHand.setJoyClickNum(cencesNewHand.getJoyClickNum() + (null == singleCencesNewHand.getJoyClickNum() ? 0 : singleCencesNewHand.getJoyClickNum()));
        cencesNewHand.setJoyFinishNum(cencesNewHand.getJoyFinishNum() + (null == singleCencesNewHand.getJoyFinishNum() ? 0 : singleCencesNewHand.getJoyFinishNum()));

        //"访问权限开启"
//        cencesNewHand.setAccessopenClickNum(cencesNewHand.getAccessopenClickNum()+(null==singleCencesNewHand.getAccessopenClickNum()?0:singleCencesNewHand.getAccessopenClickNum()));
//        cencesNewHand.setAccessopenFinishNum(cencesNewHand.getAccessopenFinishNum()+(null==singleCencesNewHand.getAccessopenFinishNum()?0:singleCencesNewHand.getAccessopenFinishNum()));

        //"走路赚"
        cencesNewHand.setWalkClickNum(cencesNewHand.getWalkClickNum()+(null==singleCencesNewHand.getWalkClickNum()?0:singleCencesNewHand.getWalkClickNum()));
        cencesNewHand.setWalkFinishNum(cencesNewHand.getWalkFinishNum()+(null==singleCencesNewHand.getWalkFinishNum()?0:singleCencesNewHand.getWalkFinishNum()));

        //"鱼玩盒子"
//        cencesNewHand.setFishboxClickNum(cencesNewHand.getFishboxClickNum()+(null==singleCencesNewHand.getFishboxClickNum()?0:singleCencesNewHand.getFishboxClickNum()));
//        cencesNewHand.setFishboxFinishNum(cencesNewHand.getFishboxFinishNum()+(null==singleCencesNewHand.getFishboxFinishNum()?0:singleCencesNewHand.getFishboxFinishNum()));

        // "第二次每日必赚"
        cencesNewHand.setSecondEarndayClickNum(cencesNewHand.getSecondEarndayClickNum()+(null==singleCencesNewHand.getSecondEarndayClickNum()?0:singleCencesNewHand.getSecondEarndayClickNum()));
        cencesNewHand.setSecondEarndayFinishNum(cencesNewHand.getSecondEarndayFinishNum()+(null==singleCencesNewHand.getSecondEarndayFinishNum()?0:singleCencesNewHand.getSecondEarndayFinishNum()));

        // "第三次每日必赚"
        cencesNewHand.setThirdEarndayClickNum(cencesNewHand.getThirdEarndayClickNum()+(null==singleCencesNewHand.getThirdEarndayClickNum()?0:singleCencesNewHand.getThirdEarndayClickNum()));
        cencesNewHand.setThirdEarndayFinishNum(cencesNewHand.getThirdEarndayFinishNum()+(null==singleCencesNewHand.getThirdEarndayFinishNum()?0:singleCencesNewHand.getThirdEarndayFinishNum()));
    }

    /**
     * 设置其他属性
     *
     * @param time          日期
     * @param category      用户类型
     * @param brand         渠道
     * @param cencesNewHand 新手任务
     */
    private void setOtherFild(int time, int category, String brand, CencesNewHand cencesNewHand) {

        cencesNewHand.setTime(time);
        cencesNewHand.setType(0);
        cencesNewHand.setCategory(category);
        cencesNewHand.setBrand(brand);
        cencesNewHand.setCreateTime(LocalDate.now());

    }

    /**
     * 单渠道老用户
     *
     * @return 返回值
     */
    private CencesNewHand getSingleOldTask(Integer id, LocalDateTime star, LocalDateTime end, String s, CencesNewHand singleOldCencesNewHand, Map<String,List<NewHandRecordCount>> map, Map<Integer,List<TaskRewards>> allTaskRewardsMap) {

        LocalDate date = star.toLocalDate();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyyMMdd");
        String dateStr = date.format(fmt);
        TaskRewards taskRewards = null!=allTaskRewardsMap.get(id)?allTaskRewardsMap.get(id).get(0):null;
        if (null == taskRewards) {

            return setByTask(id, singleOldCencesNewHand, 0, 0, BigDecimal.ZERO);
        }

       // Integer newFinishTask = this.taskRewardsRecordMapper.selectOldFinishTask(star, end, taskRewards.getId(), s);
        //获取老用户完成量
        Integer newFinishTask = getFinishTask(taskRewards.getId(),s,map);
        int newClickTask = 0;
        String res = redisClient.hget(newHandKey + dateStr, taskRewards.getId().toString() + ":" + s + ":oldUser");
        if (null != res) {
            newClickTask = Integer.parseInt(res);
        }
        BigDecimal newFinishRate = BigDecimal.ZERO;
        if (newClickTask != 0) {
            newFinishRate = BigDecimal.valueOf(newFinishTask).divide(BigDecimal.valueOf(newClickTask), 2, BigDecimal.ROUND_DOWN);
        }

        return setByTask(id, singleOldCencesNewHand, newFinishTask, newClickTask, newFinishRate);


    }

    /**
     * 单渠道新用户
     *
     * @param id   任务id
     * @param star 开始日期
     * @param end  结束日期
     * @param s    渠道
     * @return 返回数据
     */
    private CencesNewHand getSingleNewTask(Integer id, LocalDateTime star, LocalDateTime end, String s, CencesNewHand singleNewCencesNewHand, Map<String,List<NewHandRecordCount>> map, Map<Integer,List<TaskRewards>> allTaskRewardsMap ) {

        LocalDate date = star.toLocalDate();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyyMMdd");
        String dateStr = date.format(fmt);
        TaskRewards taskRewards = null!=allTaskRewardsMap.get(id)?allTaskRewardsMap.get(id).get(0):null;
        if (null == taskRewards) {
            return setByTask(id, singleNewCencesNewHand, 0, 0, BigDecimal.ZERO);
        }

        //Integer newFinishTask = this.taskRewardsRecordMapper.selectnewFinishTask(star, end, taskRewards.getId(), s);
        //获取新用户完成量
        Integer newFinishTask = getFinishTask(taskRewards.getId(),s,map);
        int newClickTask = 0;
        String res = redisClient.hget(newHandKey + dateStr, taskRewards.getId().toString() + ":" + s + ":newUser");
        if (null != res) {
            newClickTask = Integer.parseInt(res);
        }
        BigDecimal newFinishRate = BigDecimal.ZERO;
        if (newClickTask != 0) {
            newFinishRate = BigDecimal.valueOf(newFinishTask).divide(BigDecimal.valueOf(newClickTask), 2, BigDecimal.ROUND_DOWN);
        }
        return setByTask(id, singleNewCencesNewHand, newFinishTask, newClickTask, newFinishRate);

    }

    /**
     * 获取完成量
     * @param rewardsId 任务id
     * @param appStore 渠道
     * @param map 新手任务完成量
     * @return 返回内容
     */
    private Integer getFinishTask(Integer rewardsId, String appStore, Map<String, List<NewHandRecordCount>> map) {

        AtomicInteger a=new AtomicInteger(0);
        List<NewHandRecordCount> newHandRecordCountList = map.get(appStore+":"+rewardsId);
        if(null==newHandRecordCountList){
            return a.get();
        }
        newHandRecordCountList.forEach(s->{
            a.addAndGet(s.getCount());
        });
        return a.get();
    }


    /**
     * 单渠道全部用户
     */
    private CencesNewHand getSingleAllTask(Integer id, LocalDateTime star, LocalDateTime end, String s, CencesNewHand singleAllCencesNewHand, Map<String,List<NewHandRecordCount>> map, Map<Integer,List<TaskRewards>> allTaskRewardsMap) {

        LocalDate date = star.toLocalDate();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyyMMdd");
        String dateStr = date.format(fmt);

        TaskRewards taskRewards = null!=allTaskRewardsMap.get(id)?allTaskRewardsMap.get(id).get(0):null;
        if (null == taskRewards) {
            return setByTask(id, singleAllCencesNewHand, 0, 0, BigDecimal.ZERO);
        }


        //Integer allFinishTask = this.taskRewardsRecordMapper.selectFinishTask(star, end, taskRewards.getId(), s);
        //获取全部用户完成量
        Integer allFinishTask = getFinishTask(taskRewards.getId(),s,map);

        int allClickTask = 0;
        String res = redisClient.hget(newHandKey + dateStr, taskRewards.getId().toString() + ":" + s + ":allUser");
        if (null != res) {
            allClickTask = Integer.parseInt(res);
        }

        BigDecimal allFinishRate = BigDecimal.ZERO;
        if (allClickTask != 0) {
            allFinishRate = BigDecimal.valueOf(allFinishTask).divide(BigDecimal.valueOf(allClickTask), 2, BigDecimal.ROUND_DOWN);
        }


        return setByTask(id, singleAllCencesNewHand, allFinishTask, allClickTask, allFinishRate);
    }

    /**
     * 根据新手任务设值
     */
    private CencesNewHand setByTask(Integer newHandTaskId, CencesNewHand cencesNewHand, Integer finish, Integer click, BigDecimal finishRate) {
        switch (newHandTaskId) {
            case 1:
                //小试牛刀
                cencesNewHand.setClickNum(click);
                cencesNewHand.setFinishNum(finish);
                cencesNewHand.setFinishRate(finishRate);
                break;
            case 5:
                //新手红包
                cencesNewHand.setNewhandClickNum(click);
                cencesNewHand.setNewhandFinishNum(finish);
                cencesNewHand.setNewhandFinishRate(finishRate);
                break;
            case 6:
                //赚钱攻略
                cencesNewHand.setEarnwayClickNum(click);
                cencesNewHand.setEarnwayFinishNum(finish);
                cencesNewHand.setEarnwayFinishRate(finishRate);
                break;
            case 7:
                //开安装权限
                cencesNewHand.setInstallClickNum(click);
                cencesNewHand.setInstallFinishNum(finish);
                cencesNewHand.setInstallFinishRate(finishRate);
                break;
            case 20:
                //开访问权限
                cencesNewHand.setAccessClickNum(click);
                cencesNewHand.setAccessFinishNum(finish);
                cencesNewHand.setAccessFinishRate(finishRate);
                break;
            case 21:
                //开推送权限
                cencesNewHand.setPushClickNum(click);
                cencesNewHand.setPushFinishNum(finish);
                cencesNewHand.setPushFinishRate(finishRate);
                break;
            case 38:
                //截图任务
                cencesNewHand.setPictureClickNum(click);
                cencesNewHand.setPictureFinishNum(finish);
                cencesNewHand.setPictureFinishRate(finishRate);
                break;
            case 39:
                //试玩任务
                cencesNewHand.setDemoClickNum(click);
                cencesNewHand.setDemoFinishNum(finish);
                cencesNewHand.setDemoFinishRate(finishRate);
                break;
            case 40:
                //高额任务
                cencesNewHand.setHighClickNum(click);
                cencesNewHand.setHighFinishNum(finish);
                cencesNewHand.setHighFinishRate(finishRate);
                break;
            case 41:
                //微信小程序任务
                cencesNewHand.setWechatClickNum(click);
                cencesNewHand.setWechatFinishNum(finish);
                cencesNewHand.setWechatFinishRate(finishRate);
                break;
            case 42:
                //多游试玩
                cencesNewHand.setGamedemoClickNum(click);
                cencesNewHand.setGamedemoFinishNum(finish);
                cencesNewHand.setGamedemoFinishRate(finishRate);
                break;
            case 43:
                //PC蛋蛋
                cencesNewHand.setPceggClickNum(click);
                cencesNewHand.setPceggFinishNum(finish);
                cencesNewHand.setPceggFinishRate(finishRate);
                break;
            case 44:
                //聚享玩
                cencesNewHand.setEnjoygameClickNum(click);
                cencesNewHand.setEnjoygameFinishNum(finish);
                cencesNewHand.setEnjoygameFinishRate(finishRate);
                break;
            case 45:
                //91淘金试玩
                cencesNewHand.setGolddemoClickNum(click);
                cencesNewHand.setGolddemoFinishNum(finish);
                cencesNewHand.setGolddemoFinishRate(finishRate);
                break;
            case 46:
                //搜搜任务
                cencesNewHand.setSosoClickNum(click);
                cencesNewHand.setSosoFinishNum(finish);
                cencesNewHand.setSosoFinishRate(finishRate);
                break;
            case 47:
                //搜搜糯米狗任务
                cencesNewHand.setSosodogClickNum(click);
                cencesNewHand.setSosodogFinishNum(finish);
                cencesNewHand.setSosodogFinishRate(finishRate);
                break;
            case 48:
                //完成搜搜兼职咸鱼任务
                cencesNewHand.setSosofishClickNum(click);
                cencesNewHand.setSosofishFinishNum(finish);
                cencesNewHand.setSosofishFinishRate(finishRate);
                break;
            case 49:
                //每日必赚
                cencesNewHand.setEarndayClickNum(click);
                cencesNewHand.setEarndayFinishNum(finish);
                cencesNewHand.setEarndayFinishRate(finishRate);
                break;
            case 50:
                //新闻赚
                cencesNewHand.setNewsClickNum(click);
                cencesNewHand.setNewsFinishNum(finish);
                cencesNewHand.setNewsFinishRate(finishRate);
                break;
            case 51:
                //笑话赚
                cencesNewHand.setJoyClickNum(click);
                cencesNewHand.setJoyFinishNum(finish);
                cencesNewHand.setJoyFinishRate(finishRate);
                break;
            case 52:
                //访问权限开启
                cencesNewHand.setAccessopenClickNum(click);
                cencesNewHand.setAccessopenFinishNum(finish);
                cencesNewHand.setAccessopenFinishRate(finishRate);
                break;
            case 57:
                //走路赚
                cencesNewHand.setWalkClickNum(click);
                cencesNewHand.setWalkFinishNum(finish);
                cencesNewHand.setWalkFinishRate(finishRate);
                break;
            case 54:
                //鱼玩盒子
                cencesNewHand.setFishboxClickNum(click);
                cencesNewHand.setFishboxFinishNum(finish);
                cencesNewHand.setFishboxFinishRate(finishRate);
                break;
            case 61:
                //第二次每日必赚
                cencesNewHand.setSecondEarndayClickNum(click);
                cencesNewHand.setSecondEarndayFinishNum(finish);
                cencesNewHand.setSecondEarndayFinishRate(finishRate);
                break;
            case 62:
                //第三次每日必赚
                cencesNewHand.setThirdEarndayClickNum(click);
                cencesNewHand.setThirdEarndayFinishNum(finish);
                cencesNewHand.setThirdEarndayFinishRate(finishRate);
                break;
            default:
                break;
        }

        return cencesNewHand;
    }


    /**
     * 设置导出的数据
     *
     * @param masters 导出的内容
     * @return 返回数据
     */
    public List<CencesNewHandModel> setExportData(List<CencesNewHand> masters) {
        List<CencesNewHandModel> data = new ArrayList<>();
        for (CencesNewHand cencesNewHand : masters) {
            CencesNewHandModel cencesNewHandModel = new CencesNewHandModel();
            cencesNewHandModel.setTime(cencesNewHand.getTime());
            if (cencesNewHand.getCategory() == 0) {
                cencesNewHandModel.setCategory("老用户");
            } else if (cencesNewHand.getCategory() == 1) {
                cencesNewHandModel.setCategory("新用户");
            } else if (cencesNewHand.getCategory() == 2) {
                cencesNewHandModel.setCategory("全部用户");
            } else {
                cencesNewHandModel.setCategory(cencesNewHand.getCategory().toString());
            }

            if ("all".equals(cencesNewHand.getBrand())) {
                cencesNewHandModel.setBrand("全部渠道");
            } else {
                cencesNewHandModel.setBrand(cencesNewHand.getBrand());
            }

            cencesNewHandModel.setClickNum(cencesNewHand.getClickNum());
            cencesNewHandModel.setFinishNum(cencesNewHand.getFinishNum());
            cencesNewHandModel.setFinishRate(cencesNewHand.getFinishRate()==null?"0.0%":cencesNewHand.getFinishRate().doubleValue() * 100 + "%");
            cencesNewHandModel.setEarnwayClickNum(cencesNewHand.getEarnwayClickNum());
            cencesNewHandModel.setEarnwayFinishNum(cencesNewHand.getEarnwayFinishNum());
            cencesNewHandModel.setEarnwayFinishRate(cencesNewHand.getEarnwayFinishRate()==null?"0.0%":cencesNewHand.getEarnwayFinishRate().doubleValue() * 100 + "%");
            cencesNewHandModel.setInstallClickNum(cencesNewHand.getInstallClickNum());
            cencesNewHandModel.setInstallFinishNum(cencesNewHand.getInstallFinishNum());
            cencesNewHandModel.setInstallFinishRate(cencesNewHand.getInstallFinishRate()==null?"0.0%":cencesNewHand.getInstallFinishRate().doubleValue() * 100 + "%");
            cencesNewHandModel.setAccessClickNum(cencesNewHand.getAccessClickNum());
            cencesNewHandModel.setAccessFinishNum(cencesNewHand.getAccessFinishNum());
            cencesNewHandModel.setAccessFinishRate(cencesNewHand.getAccessFinishRate()==null?"0.0%":cencesNewHand.getAccessFinishRate().doubleValue() * 100 + "%");
            cencesNewHandModel.setPushClickNum(cencesNewHand.getPushClickNum());
            cencesNewHandModel.setPushFinishNum(cencesNewHand.getPushFinishNum());
            cencesNewHandModel.setPushFinishRate(cencesNewHand.getPushFinishRate()==null?"0.0%":cencesNewHand.getPushFinishRate().doubleValue() * 100 + "%");

            cencesNewHandModel.setPictureClickNum(cencesNewHand.getPictureClickNum());
            cencesNewHandModel.setPictureFinishNum(cencesNewHand.getPictureFinishNum());
            cencesNewHandModel.setPictureFinishRate(cencesNewHand.getPictureFinishRate()==null?"0.0%":cencesNewHand.getPictureFinishRate().doubleValue() * 100 + "%");

            cencesNewHandModel.setHighClickNum(cencesNewHand.getHighClickNum());
            cencesNewHandModel.setHighFinishNum(cencesNewHand.getHighFinishNum());
            cencesNewHandModel.setHighFinishRate(cencesNewHand.getHighFinishRate()==null?"0.0%":cencesNewHand.getHighFinishRate().doubleValue() * 100 + "%");

            cencesNewHandModel.setEarndayClickNum(cencesNewHand.getEarndayClickNum());
            cencesNewHandModel.setEarndayFinishNum(cencesNewHand.getEarndayFinishNum());
            cencesNewHandModel.setEarndayFinishRate(cencesNewHand.getEarndayFinishRate()==null?"0.0%":cencesNewHand.getEarndayFinishRate().doubleValue() * 100 + "%");

            cencesNewHandModel.setJoyClickNum(cencesNewHand.getJoyClickNum());
            cencesNewHandModel.setJoyFinishNum(cencesNewHand.getJoyFinishNum());
            cencesNewHandModel.setJoyFinishRate(cencesNewHand.getJoyFinishRate()==null?"0.0%":cencesNewHand.getJoyFinishRate().doubleValue() * 100 + "%");

            cencesNewHandModel.setWalkClickNum(cencesNewHand.getWalkClickNum());
            cencesNewHandModel.setWalkFinishNum(cencesNewHand.getWalkFinishNum());
            cencesNewHandModel.setWalkFinishRate(cencesNewHand.getWalkFinishRate()==null?"0.0%":cencesNewHand.getWalkFinishRate().doubleValue()*100+"%");

            cencesNewHandModel.setSecondEarndayClickNum(cencesNewHand.getSecondEarndayClickNum());
            cencesNewHandModel.setSecondEarndayFinishNum(cencesNewHand.getSecondEarndayFinishNum());
            cencesNewHandModel.setSecondEarndayFinishRate(cencesNewHand.getSecondEarndayFinishRate()==null?"0.0%":cencesNewHand.getSecondEarndayFinishRate().doubleValue()*100+"%");

            cencesNewHandModel.setThirdEarndayClickNum(cencesNewHand.getThirdEarndayClickNum());
            cencesNewHandModel.setThirdEarndayFinishNum(cencesNewHand.getThirdEarndayFinishNum());
            cencesNewHandModel.setThirdEarndayFinishRate(cencesNewHand.getThirdEarndayFinishRate()==null?"0.0%":cencesNewHand.getThirdEarndayFinishRate().doubleValue()*100+"%");

            data.add(cencesNewHandModel);
        }
        return data;
    }

    public List<CencesNewHand> sumData(String likeBrand, Long page, Integer limit, Integer star, Integer end) {

       return baseMapper.sumData(likeBrand,page,limit,star,end,MyConfig.getEnv());

    }

    public Long countData(String likeBrand, Integer star, Integer end) {
        return  baseMapper.countData(likeBrand,star,end,MyConfig.getEnv());
    }

    public void deleteByTime(Integer time) {
        CencesNewHandExample cencesNewHandExample = new CencesNewHandExample();
        cencesNewHandExample.createCriteria().andTimeEqualTo(time).andAppIdEqualTo(MyConfig.getEnv());
        baseMapper.deleteByExample(cencesNewHandExample);
    }
}
